﻿using FreeSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XUCore.Paging;

namespace XUCore.NetCore.FreeSql
{
    /// <summary>
    /// ISelect 扩展
    /// </summary>
    public static class ISelectExtensions
    {
        /// <summary>
        /// 查询多少条数据
        /// </summary>
        /// <param name="query"></param>
        /// <param name="condition">true 时生效</param>
        /// <param name="limit">数量</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static ISelect<T> LimitIf<T>(
            this ISelect<T> query,
            bool condition,
            int limit)
        {
            if (condition)
                return query.Limit(limit);

            return query;
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="select">列表转换</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <returns></returns>
        public static List<TReturn> ToList<T, TReturn>(this ISelect<T> query, bool includeNestedMembers, Func<List<T>, List<TReturn>> select)
        {
            var list = query.ToList(includeNestedMembers);

            return select.Invoke(list);
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="select">列表转换</param>
        /// <returns></returns>
        public static List<TReturn> ToList<T, TReturn>(this ISelect<T> query, Func<List<T>, List<TReturn>> select)
        {
            var list = query.ToList();

            return select.Invoke(list);
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="select">列表转换</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<List<TReturn>> ToListAsync<T, TReturn>(this ISelect<T> query, bool includeNestedMembers, Func<List<T>, List<TReturn>> select, CancellationToken cancellationToken)
        {
            var list = await query.ToListAsync(includeNestedMembers, cancellationToken);

            return select.Invoke(list);
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="select">列表转换</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<List<TReturn>> ToListAsync<T, TReturn>(this ISelect<T> query, Func<List<T>, List<TReturn>> select, CancellationToken cancellationToken)
        {
            var list = await query.ToListAsync(cancellationToken);

            return select.Invoke(list);
        }

        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<T> ToPagedList<T>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<T>();

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<T>();

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<T> ToPagedList<T>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool includeNestedMembers,
            bool defaultEndPage = false)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(includeNestedMembers);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(includeNestedMembers);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TDto"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TDto> ToPagedList<T, TDto>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TDto>();

                return new PagedList<TDto>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TDto>();

                return new PagedList<TDto>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T, TReturn>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            Expression<Func<T, TReturn>> select,
            bool defaultEndPage = false)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select">列表转换</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T, TReturn>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool includeNestedMembers,
            Func<List<T>, List<TReturn>> select,
            bool defaultEndPage = false)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(includeNestedMembers);

                var returns = select.Invoke(list);

                return new PagedList<TReturn>(returns, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(includeNestedMembers);

                var returns = select.Invoke(list);

                return new PagedList<TReturn>(returns, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<T>> ToPagedListAsync<T>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<T>(cancellationToken);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<T>(cancellationToken);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<T>> ToPagedListAsync<T>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool includeNestedMembers,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(includeNestedMembers, cancellationToken);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(includeNestedMembers, cancellationToken);

                return new PagedList<T>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TDto"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TDto>> ToPagedListAsync<T, TDto>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TDto>(cancellationToken);

                return new PagedList<TDto>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TDto>(cancellationToken);

                return new PagedList<TDto>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T, TReturn>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            Expression<Func<T, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select">列表转换</param>
        /// <param name="includeNestedMembers">false: 返回 2级 Join 的数据；true: 返回所有层级深度 Join 的导航数据；</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T, TReturn>(
            this ISelect<T> query,
            int currentPage,
            int pageSize,
            bool includeNestedMembers,
            Func<List<T>, List<TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(includeNestedMembers, cancellationToken);

                var returns = select.Invoke(list);

                return new PagedList<TReturn>(returns, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(includeNestedMembers, cancellationToken);

                var returns = select.Invoke(list);

                return new PagedList<TReturn>(returns, count, currentPage, pageSize);
            }
        }
        #endregion


        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, TReturn>(
            this ISelect<T1, T2> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, TReturn>(
            this ISelect<T1, T2> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, TReturn>> select,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, TReturn>(
            this ISelect<T1, T2> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, TReturn>(
            this ISelect<T1, T2> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion


        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, TReturn>(
            this ISelect<T1, T2, T3> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, TReturn>(
            this ISelect<T1, T2, T3> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, TReturn>> select,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, TReturn>(
            this ISelect<T1, T2, T3> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, TReturn>(
            this ISelect<T1, T2, T3> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion


        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, TReturn>(
            this ISelect<T1, T2, T3, T4> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, TReturn>(
            this ISelect<T1, T2, T3, T4> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, TReturn>> select,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, TReturn>(
            this ISelect<T1, T2, T3, T4> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, TReturn>(
            this ISelect<T1, T2, T3, T4> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion

        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, TReturn>(
            this ISelect<T1, T2, T3, T4, T5> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, TReturn>(
            this ISelect<T1, T2, T3, T4, T5> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, T5, TReturn>> select,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, TReturn>(
            this ISelect<T1, T2, T3, T4, T5> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, TReturn>(
            this ISelect<T1, T2, T3, T4, T5> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, T5, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion


        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, T6, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, T6, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select,
            bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, T6, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, T6, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion

        #region ToPagedList(分页)

        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, T6, T7, TReturn>(
                this ISelect<T1, T2, T3, T4, T5, T6, T7> query,
                int currentPage,
                int pageSize,
                bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
            where T7 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList<TReturn>();

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <returns></returns>
        public static PagedList<TReturn> ToPagedList<T1, T2, T3, T4, T5, T6, T7, TReturn>(
                this ISelect<T1, T2, T3, T4, T5, T6, T7> query,
                int currentPage,
                int pageSize,
                Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select,
                bool defaultEndPage = false)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
            where T7 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = query.Count();

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = query.Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = query.Count(out var count).Page(currentPage, pageSize).ToList(select);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, T6, T7, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6, T7> query,
            int currentPage,
            int pageSize,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
            where T7 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync<TReturn>(cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        /// <summary>
        /// 创建分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="query">查询条件</param>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="select"></param>
        /// <param name="defaultEndPage">默认false，且页码必须&lt;=0，在特殊需求上可以使用，比如评论需要保证顺序的情况下，默认最新评论显示最后一页</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<PagedList<TReturn>> ToPagedListAsync<T1, T2, T3, T4, T5, T6, T7, TReturn>(
            this ISelect<T1, T2, T3, T4, T5, T6, T7> query,
            int currentPage,
            int pageSize,
            Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select,
            bool defaultEndPage = false,
            CancellationToken cancellationToken = default)
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
            where T6 : class
            where T7 : class
        {
            if (defaultEndPage && currentPage <= 0)
            {
                var count = await query.CountAsync(cancellationToken);

                if (currentPage <= 0) currentPage = PagedTools.TotalPage(pageSize, count);

                var list = await query.Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
            else
            {
                var list = await query.Count(out var count).Page(currentPage, pageSize).ToListAsync(select, cancellationToken);

                return new PagedList<TReturn>(list, count, currentPage, pageSize);
            }
        }
        #endregion
    }
}
